<?php
/**
 * Created by PhpStorm.
 * User: Lyq
 * Date: 2018/8/22
 * Time: 上午8:21
 */
namespace app\admin\controller;

use think\Exception;
use think\Db;

class Order extends Common
{
    //订单列表
    public function index()
    {
        $this->templateTitle('订单列表');
        $this->assign('type_list',get_order_type('',2));
        $this->assign('pay_status_list',get_pay_status('',2));
        $this->assign('count_status_list',get_count_status('',2));
        //判断条件
        $where['or.id']=['gt',0];


        //搜索条件-用户
        $user_condition = request()->param("user_condition");
        $this->assign("user_condition", $user_condition);
        if ($user_condition)
        {
            $where["us.real_name|us.mobile|us.id"] = $user_condition;
        }

        //搜索条件-联盟商
        $un_condition = request()->param("un_condition");
        $this->assign("un_condition", $un_condition);
        if ($un_condition)
        {
            $where["un.title|un.id"] = $un_condition;
        }

        //搜索条件-活动主题
        $ac_condition = request()->param("ac_condition");
        $this->assign("ac_condition", $ac_condition);
        if ($ac_condition)
        {
            $where["ac.title|ac.id"] = $ac_condition;
        }

        //搜索条件-订单
        $or_condition = request()->param("or_condition");
        $this->assign("or_condition", $or_condition);
        if ($or_condition)
        {
            $where["or.id|or.orderid"] = $or_condition;
        }

        //搜索条件-订单类型
        $order_type = request()->param('order_type');
        $this->assign('order_type',$order_type);
        if($order_type){
            $where["or.order_type"] = $order_type;
        }

        //支付状态
        $pay_status = request()->param('pay_status');
        $this->assign('pay_status',$pay_status);
        if($pay_status!=''){
            $where['or.pay_status'] = $pay_status;
        }

        //H链结算状态
        $count_status = request()->param('count_status');
        $this->assign('count_status',$count_status);
        if($count_status!=''){
            $where['or.count_status'] = $count_status;
        }

        //搜索条件-注册时间
        if (request()->has("time_range"))
        {
            //解析时间
            $timeRange = request()->param("time_range");
            $timeRange = explode(" ~ ", $timeRange);
            //模板渲染值
            $this->assign("range_start", ["time_range" => $timeRange[0]]);
            $this->assign("range_end", ["time_range" => $timeRange[1]]);

            $where['or.create_time'] = ["BETWEEN", [strtotime($timeRange[0] . " 00:00:00"),strtotime($timeRange[1] . " 23:59:59")]];

        }
        else
        {
            //模板渲染值
            $this->assign("range_start", ["time_range" => '1970-01-01']);
            $this->assign("range_end", ["time_range" => date("Y-m-d")]);
        }

        //获取评价列表
        $list = Db::name("order")
            ->alias('or')
            ->join('__USER__ us','us.id=or.uid','LEFT')
            ->join('__UNION__ un','un.id=or.union_id','LEFT')
            ->join('__ACTIVE__ ac','ac.id=or.active_id','LEFT')
            ->where($where)
            ->order("or.id DESC")
            ->field('or.*,us.real_name as uname,us.mobile as umobile,un.title as untitle,ac.title as actitle')
            ->paginate(10);

        $this->assign("list", $list);

        return $this->fetch();
    }



}